<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Newproduct_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	/*
	 * 根据分页信息得到新品
	 */
	public function find_all_newproducts($per_page,$offset){
		$this->db->select('t_newproduct.id,t_newproduct.name,t_newproduct.description,t_newproduct.amount,t_newproduct.userid,t_user.contact,t_user.shopname,t_newproduct.submit_time,t_newproduct.reply');
		$this->db->from('t_newproduct');
		$this->db->join('t_user', 't_newproduct.userid = t_user.id','left');
		$this->db->limit($per_page, $offset);
		$this->db->order_by("id", "desc");
		$query = $this->db->get();
		return $query->result_array();
	}
	/*
	 * 返回所有新品的数量
	 */
	public function count_newproducts(){
		$query = $this->db->get('t_newproduct');
		return $query->num_rows();
	}
	/*
	 * 根据ID得到新品信息
	 */
	public function load($id){
		$query = $this->db->get_where('t_newproduct',array('id' => $id));
		if ($row = $query->row_array()){
			return $row;
		}
		return array();
	}
	/*
	 *更新新品信息
	 */
	public function update($id,$newproduct){
		$this->db->where('id', $id);
		$this->db->update('t_newproduct', $newproduct);
		return $this->db->affected_rows()>0;
	}
}